<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Login Page</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 样 式 文 件 -->
    <link rel="stylesheet" href="{_STATIC_PATH}component/pear/css/pear.css"/>
</head>
<body>
<form class="layui-form layui-form-pane" lay-filter="lotus-edit-filter">

    <div class="layui-form-item" style="display: none">
        <label class="layui-form-label">id</label>
        <div class="layui-input-block">
            <input type="text" name="id" lay-verify="required" value=""
                   autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">
            上级权限
        </label>
        <div class="layui-input-block">
            <select lay-filter="aihao" name="pid">
                <option value="0">顶级权限</option>
                {volist name='author' id='vo'}
                <option value="{$vo.id}">{$vo.level-1|str_repeat='丨--',###}{$vo.title}</option>
                {/volist}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">权限名称</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">路由</label>
        <div class="layui-input-block">
            <input type="text" name="href" placeholder="例如:/admin/user/userList" value=""
                   autocomplete="off" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label"><a target="_blank" href="https://www.layui.com/doc/element/icon.html#table">图标(点)</a></label>
        <div class="layui-input-block">
            <input type="text" id="iconPicker" name="icon" value="layui-icon-cellphone" lay-filter="iconPicker"
                   style="display: none;">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">排序权重</label>
        <div class="layui-input-block">
            <input type="number" value="0" name="sort" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">
            状态
        </label>
        <div class="layui-input-block">
            <select lay-filter="aihao" name="status">
                <option value="1">显示</option>
                <option value="2">隐藏</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">
            类型
        </label>
        <div class="layui-input-block">
            <select lay-filter="aihao" name="type">
                <option value="0">目录</option>
                <option value="1">功能</option>
            </select>
        </div>
    </div>
    <div>{:token_field()}</div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn layui-btn-submit" lay-submit lay-filter="save">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
<script src="{_STATIC_PATH}component/layui/layui.js"></script>
<script src="{_STATIC_PATH}component/pear/pear.js"></script>
<script>
    layui.use(['form', "iconPicker", "jquery"], function () {
        var form = layui.form,
            iconPicker = layui.iconPicker,
            $ = layui.jquery;
        var data = {
            "id": "{$data.id}",
            'title': "{$data.title}",
            "pid": "{$data.pid}",
            'icon': "{$data.icon}",
            'sort': "{$data.sort}",
            'href': "{$data.href}",
            'status': "{$data.status}",
            'type': "{$data.type}",
        };
        form.val("lotus-edit-filter", data);
        iconPicker.render({
            elem: '#iconPicker',
            type: 'fontClass',
            search: true,
            page: false,
            limit: 16,
            click: function (data) {
                console.log(data);
            },
            success: function (d) {
                console.log(d);
            }
        });

        form.on('submit(save)', function (data) {
            $.ajax({
                url: '',
                type: "post",
                data: data.field,
                success: function (result) {
                    if (result.status == "1") {
                        layer.msg(result.message, function () {
                            parent.location.reload();
                        });
                    } else {
                        layer.msg(result.message);
                    }
                }
            })
        });
    });
</script>
</body>
</html>